<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
    <style>
        .layui-card {
            border: 1px solid #f2f2f2;
            border-radius: 5px;
        }

        .layuimini-qiuck-module a i {
            display: inline-block;
            width: 100%;
            height: 60px;
            line-height: 60px;
            text-align: center;
            border-radius: 2px;
            font-size: 30px;
            background-color: #F8F8F8;
            color: #333;
            transition: all .3s;
            -webkit-transition: all .3s;
        }

        .layuimini-qiuck-module a cite {
            position: relative;
            top: 2px;
            display: block;
            color: #666;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
            font-size: 14px;
        }

        .welcome-module {
            width: 100%;
        }

        .panel {
            background-color: #fff;
            border: 1px solid transparent;
            border-radius: 3px;
            -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
            box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
            text-align: center;
        }

        .panel-body {
            padding: 10px
        }

        .panel-title {
            margin-top: 0;
            margin-bottom: 0;
            font-size: 12px;
            color: inherit
        }

        .main_btn > p {
            height: 40px;
        }

        .layui-bg-number {
            background-color: #F8F8F8;
        }

        .no-margins {
            color: #00a2d4;
        }
        .layui-table-cell {
            height:auto;
        }
        li:first-child
        {
            border:none;
        }
        li {
            border-top:solid 1px #e6e6e6;
            padding:10px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">
            <div style="margin: 10px 10px 10px 10px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">搜索信息</label>
                        <div class="layui-input-inline" style="width: 250px">
                            <input type="text" name="search" autocomplete="off" placeholder="按【团队名称】【领导人手机号】搜索" class="layui-input soso">
                        </div>
                    </div>
                    <div class="layui-inline" style="display: none">
                        <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                    </div>
                </div>

            </div>
        </form>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="bentchAdd">批量投放</button>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="lanunch">投放管理</button>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="LaunchIndustry">投放行业</a>
        </script>
        <input type="hidden" id="memberCode">
    </div>
</div>
<script type="text/html" id="matchTpl">
    <ul>
        {{#  layui.each(d.value_section, function(index, item){ }}
        <li >
            <span style="margin-right:10px;">匹配区间：{{ index }}</span>
            <span style="margin-left:10px;">数量：{{ item }}</span>
        </li>
        {{#  }); }}

        {{#  if(d.value_section.length === 0){ }}
        无数据
        {{#  } }}
    </ul>
</script>
<script type="text/html" id="selling">
    <ul >
        {{#  layui.each(d.selling, function(index, item){ }}
        <li >
            <span style="margin-right:10px;">匹配区间：{{ item.min_num }}~{{ item.max_num }}</span>
            <span style="margin-left:10px;">数量：{{ item.num }}</span>
        </li>
        {{#  }); }}

        {{#  if(d.selling.length === 0){ }}
        无数据
        {{#  } }}
    </ul>
</script>
<script type="text/html" id="forSale">
    <ul >
        {{#  layui.each(d.forSale, function(index, item){ }}
        <li >
            <span style="margin-right:10px;">匹配区间：{{ item.min_num }}~{{ item.max_num }}</span>
            <span style="margin-left:10px;">数量：{{ item.num }}</span>
        </li>
        {{#  }); }}

        {{#  if(d.forSale.length === 0){ }}
        无数据
        {{#  } }}
    </ul>
</script>
{include file="public/footer" /}
<script>
    var level="{$level}";
    var canuselevel="{$canuselevel}";
    var industry_id="{$industry_id}";

    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        /*用户卡券*/
        table.render({
            elem: '#currentTableId',
            url: '/admin/TransactionData/proportionToBeSold?action=detail&canuselevel=' +"{$canuselevel}"+'&title='+"{$title}"+"&industry_id="+"{$industry_id}"
            +"&min_worth="+"{$min_worth}"+"&max_worth="+"{$max_worth}",
            method: 'post',
            where: {'level': "{$level}"},
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'title', title: '团队名称', sort: true, align: 'center'},
                {field: 'industry_title', title: '生意名称', sort: true, align: 'center'},
                {title: '待出售生意数量', sort: true, align: 'center',templet:"#forSale",event:'checkforsale'},
                {title: '出售中生意数量', sort: true, align: 'center',templet:"#selling",event:'checkselling'},
                {title: '待匹配数量',templet:"#matchTpl",height:'auto',event:'checkMatching',},
                {field: 'needToBuy', title: '需购买数量', sort: true, align: 'center',event:'checkNeedBuy'},
                {title: '操作', toolbar: '#currentTableBar', align: 'center'}
            ]],
            limits: [10, 15, 20, 25, 30, 50, 100],
            limit: 10,
            page: true,
            skin: 'line,row',
            done: function (res, curr, count) {

            }
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');
            return false;
        });
        /*投放行业*/
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.open({
                    type: 2,
                    title: '查看详情',
                    shadeClose: true,
                    shade: 0.5,
                    area: ['100%', '100%'],
                    content: "/admin/TransactionData/proportionToBeSold?action=detailView&level={$level}",
                    end: function () {
                        location.reload();
                    }
                });
            }
            if (obj.event === 'LaunchIndustry') {
                
                layer.prompt({title: '输入玩家ID/手机号', formType: 0}, function (searchInfo, index) {
                    layer.close(index);
                    $.ajax({
                        url: '/admin/transactionData/searchMemberInfo',
                        type: 'post',
                        dataType: 'json',
                        async: false,
                        data: {searchInfo: searchInfo},
                        success: function (res) {
                            if (res.status == true) {
                                // 关闭弹出层
                                layer.msg(res.msg);
                                layer.open({
                                    title: '投放行业',
                                    type: 2,
                                    shade: 0.2,
                                    maxmin: true,
                                    shadeClose: true,
                                    area: ['100%', '100%'],
                                    content: '/admin/TransactionData/launchIndustry?memberInfo=' + encodeURI(JSON.stringify(res.memberInfo)) + '&level=' + data.level
                                    +"&industry_title="+data.industry_title+"&industry_id="+data.industry_id+'&min_worth='+data.min_worth+'&max_worth='+data.max_worth,
                                });
                            } else {
                                layer.msg(res.msg);
                            }
                        },
                        error: function () {
                            layer.msg("报错了");
                        }
                    });
                });
            }

            if(obj.event=='checkNeedBuy'){
                if(data.needToBuy>0){
                    layer.open({
                        type: 2,
                        title: '需购买用户',
                        shadeClose: true,
                        shade: 0.5,
                        area: ['100%', '100%'],
                        content: '/admin/Member/index?lanunchdetail=1&checkmark=1&canUseLevel='+canuselevel+"&checklevel="+level+"&team_id="+data.id,
                        end: function () {
                        }
                    });
                }
            }
            if(obj.event=='checkselling'){
                if(data.selling.length>0){
                    layer.open({
                        type: 2,
                        title: '出售中用户',
                        shadeClose: true,
                        shade: 0.5,
                        area: ['100%', '100%'],
                        content: '/admin/Member/index?lanunchdetail=1&checkmark=2&canUseLevel='+canuselevel+"&checklevel="+level+"&team_id="+data.id,
                        end: function () {
                        }
                    });
                }

            }
            if(obj.event=='checkforsale'){
                if(data.forSale.length>0){
                    layer.open({
                        type: 2,
                        title: '待出售用户',
                        shadeClose: true,
                        shade: 0.5,
                        area: ['100%', '100%'],
                        content: '/admin/Member/index?lanunchdetail=1&checkmark=3&canUseLevel='+canuselevel+"&checklevel="+level+"&team_id="+data.id,
                        end: function () {
                        }
                    });
                }
            }
            if(obj.event=='checkMatching'){
                console.log(data.id);
                if(data.value_section!=""&&data.value_section!=undefined){
                    layer.open({
                        type: 2,
                        title: '匹配中用户',
                        shadeClose: true,
                        shade: 0.5,
                        area: ['100%', '100%'],
                        content: '/admin/Member/index?lanunchdetail=1&checkmark=4&canUseLevel='+canuselevel+"&checklevel="+level+"&team_id="+data.id,
                        end: function () {
                        }
                    });
                }

            }
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'bentchAdd') {  // 监听添加操作
                var index = layer.open({
                    title: '批量投放',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/TransactionData/bentch_lanunch?canuselevel=' +"{$canuselevel}"+'&title='+"{$title}"
                    +"&industry_id="+"{$industry_id}" +"&min_worth="+"{$min_worth}"+"&max_worth="+"{$max_worth}"+"&level="+"{$level}"
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }else if (obj.event === 'lanunch') {  // 监听添加操作
                var index = layer.open({
                    title: '投放管理',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/TransactionData/lanunch_list'
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });

    });

</script>

</body>
</html>